/**
 * @description 登录key
 * @type {string}
 */
const key = require('./key')
const jwt = require('jsonwebtoken')
/**
 * @description 授权验证
 * @param token
 * @returns {Promise<any>}
 */
module.exports = function (token) {
    return new Promise(function (resolve, reject) {
        try {
            jwt.verify(token, key, function (err, decode) {
                if (err) {
                    reject(new Error('无效的Authorization，或已过期！'))
                } else {
                    resolve(decode)
                }
            })
        } catch (e) {
            reject(new Error('未知的错误异常 --> verify'))
        }
    })
}